package com.mcp.converter.domain.rule.compatibility.datatype;

import com.mcp.converter.domain.checker.IncompatibilityDetail;
import com.mcp.converter.shared.response.sql.SQLElement;
import com.mcp.converter.domain.rule.compatibility.AbstractDataTypeRule;

/**
 * NCLOB数据类型兼容性规则检查器
 * OceanBase不支持NCLOB数据类型
 *
 * @author zengxiong
 */
public class NClobDataTypeRule extends AbstractDataTypeRule {

    private static final String RULE_ID = "DT004";
    private static final String RULE_NAME = "NCLOB Type Check";
    private static final String RULE_DESCRIPTION = "检查是否使用了OceanBase不支持的NCLOB数据类型";

    public NClobDataTypeRule() {
        super(RULE_ID, RULE_NAME, RULE_DESCRIPTION);
        setIncompatibilityDetail("NCLOB数据类型在OceanBase中不可用", "无法存储大文本对象", "建议转换为CLOB类型并使用UTF-8编码",
                IncompatibilityDetail.Severity.HIGH);
    }

    @Override
    public boolean matches(Object target) {
        if (target instanceof SQLElement) {
            SQLElement element = (SQLElement) target;
            if (isDataTypeElement(element)) {
                return "NCLOB".equalsIgnoreCase(element.getValue()) || "NATIONAL CHARACTER LARGE OBJECT".equalsIgnoreCase(element.getValue());
            }
        }
        return false;
    }
}